<?php

declare(strict_types=1);
/**
 * This file is part of Hyperf.
 *
 * @link     https://www.hyperf.io
 * @document https://hyperf.wiki
 * @contact  group@hyperf.io
 * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
 */

use Hyperf\Database\Commands\ModelOption;
use Hyperf\ModelCache\Handler\RedisHandler;

use function Hyperf\Support\env;

return [
    'default' => [
        'driver' => env('DB_DRIVER', 'mysql'), // 数据库引擎
        'host' => env('DB_HOST', 'localhost'), // 数据库地址
        //读写分离配置
//        'read' => [
//            'host' => ['192.168.1.1'],
//        ],
//        'write' => [
//            'host' => ['196.168.1.2'],
//        ],
//        'sticky'    => true,

        'port' => env('DB_PORT', 3306), // 数据库端口
        'database' => env('DB_DATABASE', 'hyperf'), // 数据库默认 DB
        'username' => env('DB_USERNAME', 'root'), // 数据库用户名
        'password' => env('DB_PASSWORD', ''), // 数据库密码
        'charset' => env('DB_CHARSET', 'utf8mb4'), // 数据库编码
        'collation' => env('DB_COLLATION', 'utf8mb4_unicode_ci'), // 数据库编码
        'prefix' => env('DB_PREFIX', ''), // 数据库模型前缀
        'pool' => [
            'min_connections' => 1, // 连接池内最少连接数
            'max_connections' => 10, // 连接池内最大连接数
            'connect_timeout' => 10.0, // 连接等待超时时间
            'wait_timeout' => 3.0, // 超时时间
            'heartbeat' => -1, // 心跳
            'max_idle_time' => (float) env('DB_MAX_IDLE_TIME', 60), // 最大闲置时间
        ],
        'options' => [
            // 框架默认配置
            PDO::ATTR_CASE => PDO::CASE_NATURAL,
            PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
            PDO::ATTR_ORACLE_NULLS => PDO::NULL_NATURAL,
            PDO::ATTR_STRINGIFY_FETCHES => false,
            // 如果使用的为非原生 MySQL 或云厂商提供的 DB 如从库/分析型实例等不支持 MySQL prepare 协议的, 将此项设置为 true
            PDO::ATTR_EMULATE_PREPARES => false,
        ],
        'cache' => [
            'handler' => RedisHandler::class,
            'cache_key' => '{mc:%s:m:%s}:%s:%s',
            'prefix' => 'default',
            'ttl' => 3600 * 24,
            'empty_model_ttl' => 600,
            'load_script' => true,
        ],
        'commands' => [
            'gen:model' => [
                'path' => 'app/Model',
                'force_casts' => true,
                'inheritance' => 'Model',
                'uses' => '',
                'refresh_fillable' => true,
                'table_mapping' => [],
                'with_comments' => true,
                'property_case' => ModelOption::PROPERTY_SNAKE_CASE,
//                'visitors' => [
//                    Hyperf\Database\Commands\Ast\ModelRewriteKeyInfoVisitor::class
//                ],
            ],
        ],
    ],
    'pgsql' => [
        'driver' => env('DB_PG_DRIVER', 'pgsql'),
        'host' => env('DB_PG_HOST', 'localhost'),
        'database' => env('DB_PG_DATABASE', 'hyperf'),
        'port' => env('DB_PG_PORT', 5432),
        'username' => env('DB_PG_USERNAME', 'postgres'),
        'password' => env('DB_PG_PASSWORD'),
        'charset' => env('DB_PG_CHARSET', 'utf8'),
    ],
    'sqlite' => [
        'driver' => env('DB_LITE_DRIVER', 'sqlite'),
        'host' => env('DB_LITE_HOST', 'localhost'),
        // :memory: 为内存数据库 也可以指定文件绝对路径
        'database' => env('DB_LITE_DATABASE', ':memory:'),
        // other sqlite config
    ],
    'sqlserver' => [
        'driver' => env('DB_SQL_DRIVER', 'sqlsrv'),
        'host' => env('DB_SQL_HOST', 'mssql'),
        'database' => env('DB_SQL_DATABASE', 'hyperf'),
        'port' => env('DB_SQL_PORT', 1443),
        'username' => env('DB_SQL_USERNAME', 'SA'),
        'password' => env('DB_SQL_PASSWORD'),
        'odbc_datasource_name' => 'DRIVER={ODBC Driver 18 for SQL Server};SERVER=127.0.0.1,1433;TrustServerCertificate=yes;database=hyperf',
        'odbc' => true,
    ],
];
